package server;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class WebAppClassLoader extends ClassLoader {

    private String webappPath;

    public WebAppClassLoader(String webappPath) {
        this.webappPath = webappPath;
    }

    @Override
    protected Class<?> findClass(String name) throws ClassNotFoundException {
        String classPath = name.replace(".", File.separator) + ".class";
        try {
            byte[] bytes = new FileInputStream(webappPath + File.separator + classPath).readAllBytes();
            return defineClass(name, bytes, 0 ,bytes.length);
        } catch (Exception e) {
            return null;
        }
    }
}
